/**
 * Copyright &copy; 2016-2017 <a href="http://git.oschina.net/whoamien/backend_management">Backend Management</a> All rights reserved.
 */
package com.xw.app.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.xw.app.model.SysDict;
import com.xw.framework.base.dao.BaseDAO;

/**
 * The Interface SysDictDAO.
 *
 * @author Xi Wei
 */
@Repository
public interface SysDictDAO extends BaseDAO<SysDict, Long>{

	/**
	 * Find by dict code and parent id.
	 *
	 * @param dictCode the dict code
	 * @param parentId the parent id
	 * @return the list
	 */
	//下面四个方法用于判断数据字典的代码是否存在
	public List<SysDict> findByDictCodeAndParentId(String dictCode,Long parentId);
	
	/**
	 * Find by dict code and parent id and id not.
	 *
	 * @param dictCode the dict code
	 * @param parentId the parent id
	 * @param id the id
	 * @return the list
	 */
	public List<SysDict> findByDictCodeAndParentIdAndIdNot(String dictCode,Long parentId,Long id);
	
	/**
	 * Find by dict code and parent id is null.
	 *
	 * @param dictCode the dict code
	 * @return the list
	 */
	public List<SysDict> findByDictCodeAndParentIdIsNull(String dictCode);
	
	/**
	 * Find by dict code and parent id is null and id not.
	 *
	 * @param dictCode the dict code
	 * @param id the id
	 * @return the list
	 */
	public List<SysDict> findByDictCodeAndParentIdIsNullAndIdNot(String dictCode,Long id);
	
	/**
	 * Find by parent code.
	 *
	 * @param parentCode the parent code
	 * @return the list
	 */
	public List<SysDict> findByParentCode(String parentCode);
	
	/**
	 * Gets the all parent dict.
	 *
	 * @return the all parent dict
	 */
	@Query("select t from SysDict t where exists (select k from SysDict k where k.parent.id = t.id)")
	public List<SysDict> getAllParentDict();

}
